<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>Insert title here</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="./layui/css/layui.css">
		<script src="./layui/layui.js"></script>
		<script type="text/javascript" src="js/global.js"></script>
	</head>

	<body>
			<form class="layui-form" onsubmit="false">
			<div hidden="hidden" class="layui-form-item" style="margin-top: 20px">
				<label class="layui-form-label">ID：</label>
				<div class="layui-input-inline" style="width: 350px">
					<input type="text" name="nid" id="nid" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
				<div class="layui-form-item" >
       <label class="layui-form-label" ><span style="color: red;">*</span>内容</label>
     <textarea name="content" id="content" class="layui-textarea" lay-verify="layEditContent" placeholder="请输入内容信息"></textarea>
  </div>
			<div class="layui-form-item">
				<div class="layui-btn-container" style="text-align: center;">
					<button class="layui-btn" lay-submit lay-filter="formDemo">编辑</button>
				</div>
			</div>
		</form>
		
		<script>
			
			//Demo
			layui.use(['form','layedit'], function() {
				var form = layui.form;
				var $ = layui.jquery;
				var layedit=layui.layedit;
				//解决跨域
				$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
					options.xhrFields = {
						withCredentials: true
					}
				})
				var editIndex =null;
          setTimeout(function (){
             editIndex = layedit.build('content', {
                height: 180 ,//设置编辑器高度
                tool: [
                    'strong' //加粗
                    , 'italic' //斜体
                    , 'underline' //下划线
                    , 'del' //删除线
                    , '|' //分割线
                    , 'left' //左对齐
                    , 'center' //居中对齐
                    , 'right' //右对齐
                    , 'link' //超链接
                    , 'unlink' //清除链接
                    , 'face' //表情
                    , 'help' //帮助
                ]
            });
            //获取表单前进行验证，此时已经同步了
            form.verify({
                layEditContent: function (value) {
                    return layedit.sync(editIndex);
                }
            });
            form.render('select');
        },50);
				//监听提交
				form.on('submit(formDemo)', function(data) {
					var content=layedit.getContent(editIndex);
					
					var formData  = data.field;
					var url = globalData.server + './note/update';
					$.post(url, formData, function(data) {
						console.log(data);
						if(data.count > 0) {
							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index); //再执行关闭   
						} else {
							layer.msg(data.msg, {
								icon: 6
							});
						}
					}, "json");
					return false;
				});
			});
		</script>
	</body>

</html>